#include "Std_Types.h"

#include "IOHAL.h"
#include "Dio.h"
#include "RbBaseSw.h"
#include "SubRom.h"

//#define EEPROM_START_SEC_CODE
//#include "EEPROM_MemMap.h"

uint8 test_count = 0;
unsigned char status;
unsigned short usData[130];
uint8 subrom_r;

void EEPROM_Init(void)
{
	unsigned long i = 0;
	unsigned short usSend[130] = 
	{	
		0x0101,0x0202,0x0303,0x0404,0x0505,0x0606,0x0707,0x0808,0x0909,0x0a0a,
		0x0b0b,0x0c0c,0x0d0d,0x0e0e,0x0f0f,0x1010,0x1111,0x1212,0x1313,0x1414,
		0x1515,0x1616,0x1717,0x1818,0x1919,0x1a1a,0x1b1b,0x1c1c,0x1d1d,0x1e1e,
		0x0101,0x0202,0x0303,0x0404,0x0505,0x0606,0x0707,0x0808,0x0909,0x0a0a,
		0x0b0b,0x0c0c,0x0d0d,0x0e0e,0x0f0f,0x1010,0x1111,0x1212,0x1313,0x1414,
		0x1515,0x1616,0x1717,0x1818,0x1919,0x1a1a,0x1b1b,0x1c1c,0x1d1d,0x1e1e,
		0x0101,0x0202,0x0303,0x0404,0x0505,0x0606,0x0707,0x0808,0x0909,0x0a0a,
		0x0b0b,0x0c0c,0x0d0d,0x0e0e,0x0f0f,0x1010,0x1111,0x1212,0x1313,0x1414,
		0x1515,0x1616,0x1717,0x1818,0x1919,0x1a1a,0x1b1b,0x1c1c,0x1d1d,0x1e1e,
		0x0101,0x0202,0x0303,0x0404,0x0505,0x0606,0x0707,0x0808,0x0909,0x0a0a,
		0x0b0b,0x0c0c,0x0d0d,0x0e0e,0x0f0f,0x1010,0x1111,0x1212,0x1313,0x1414,
		0x1515,0x1616,0x1717,0x1818,0x1919,0x1a1a,0x1b1b,0x1c1c,0x1d1d,0x1e1e,
		0x0101,0x0202,0x0303,0x0404,0x0505,0x0606,0x0707,0x0808,0x0909,0x0a0a,
	};
	
	test_count = 1;
	if(test_count == 1)
	{
		test_count = 2;
	}
	else
	{
		test_count = 0;
	}
	
	/*while(1)
	{
		Dio_WriteChannel(DioConf_DioChannel_M_SUBROM_W, 1);
		Dio_WriteChannel(DioConf_DioChannel_M_SUBROM_CS, 1);
		Dio_WriteChannel(DioConf_DioChannel_M_SUBROM_CLK, 1);
		subrom_r = !Dio_ReadChannel(DioConf_DioChannel_M_SUBROM_R);
		delay_us(100);
		Dio_WriteChannel(DioConf_DioChannel_M_SUBROM_W, 0);
		Dio_WriteChannel(DioConf_DioChannel_M_SUBROM_CS, 0);
		Dio_WriteChannel(DioConf_DioChannel_M_SUBROM_CLK, 0);
		subrom_r = !Dio_ReadChannel(DioConf_DioChannel_M_SUBROM_R);
		delay_us(100);
	}*/
	SubRom_Init();
	//SpiBurstWrite(128, usSend, 128);
	//SpiWriteAll(129, &usSend[2]);
	
	//while(1)
	//{
		//SpiWriteSwith(DISABLE);
		//SpiWriteOneData(1, usSend[1]);
		//SpiBurstWrite(0x0005, usSend, 1);
		
		//subrom_r = SpiReadOneData(0x000a);
		//subrom_r = SpiReadOneData(0x000b);
		//SpiBurstRead(0x00,usData,128);
		//delay_us(200);
	//}
	
	while(1)
	{
		if((status == IDLE) || (status == DONE))
		{
			ShrExp_Read_SbrmData(&status,215,40);
			ShrExp_Get_SbrmIntBuffer(&status,usData,40);
		}
		else
		{
			
		}
	}
}

//#define EEPROM_STOP_SEC_CODE
//#include "EEPROM_MemMap.h"